<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function draw() {
            var canvas = document.getElementById('canvas');
            if (canvas.getContext){
                var ctx = canvas.getContext('2d');

                // 填充三角形
                ctx.beginPath();
                ctx.moveTo(25,25);
                ctx.lineTo(105,25);
                ctx.lineTo(25,105);
                ctx.fill();

                // 描边三角形
                ctx.beginPath();
                ctx.moveTo(125,125);
                ctx.lineTo(125,45);
                ctx.lineTo(45,125);
                ctx.closePath();
                ctx.stroke();
            }
        }
    </script>
</head>
<body onload="draw()">
<canvas id="canvas" height="300px" width="300px"></canvas>
</body>
</html>